package main

import "fmt"

func main() {
	nums := []int{1, 2}

	result := subsets(nums)

	fmt.Println(result)
}

// 子集合
func subsets(nums []int) [][]int {
	var result [][]int

	if nums == nil || len(nums) == 0 {
		return result
	}

	var list []int

	dfs(nums, &result, list, 0)

	return result
}

/**
 * {1, 2}
 * [] [1] [1, 2]
 */
func dfs(nums []int, result *[][]int, list []int, start int) {
	*result = append(*result, append([]int{}, list...))

	for i := start; i < len(nums); i++ {
		list = append(list, nums[i])

		dfs(nums, result, list, i+1)

		list = list[:len(list)-1]
	}
}
